import type { Customer, CustomerApproval } from "../types/user";
import { request } from "@/service/request/request";

/**
 * 客户注册，提交注册申请待审批
 * @param customer 客户信息
 */
export const registerCustomer = async (customer: Customer) => {
    try {
        return await request<Customer>(
            "/user/customer/register",
            "post",
            customer
        );
    } catch (error) {
        throw error;
    }
};

/**
 * 获取客户账号总数
 * @returns
 */
export const getCustomerCounts = async () => {
    try {
        return await request<number>(
            "/user/get_all_customer_count",
            "post",
            null
        );
    } catch (error) {
        throw error;
    }
};

/**
 * 分页获取获取客户列表
 * @param params  { page: number; size: number; }
 * @returns
 */
export const getCustomersList = async (params: {
    page: number;
    size: number;
}) => {
    try {
        return await request<Customer[]>(
            "/user/get_all_customer_page",
            "post",
            params,
            {
                loading: false,
            }
        );
    } catch (error) {
        throw error;
    }
};

/**
 * 获取客户注册申请接口，分页获取
 * @param params { page: number; size: number; } 分页参数
 * @param model 获取模式 0：已审批 1：未审批
 * @returns
 */
export const getApprovals = async (
    params: {
        page: number;
        size: number;
    },
    model: 0 | 1
) => {
    try {
        return await request<CustomerApproval[]>(
            `/user/admin/get_page_approval/${model}`,
            "post",
            params,
            { loading: false }
        );
    } catch (error) {
        throw error;
    }
};

/**
 * 管理员审核客户注册申请
 * @param params
 * @param id 注册申请id
 * @param status 0：通过 1：拒绝
 * @param comments 审核意见，可选
 * @returns
 */
export const auditCustomerApproval = async (params: {
    id: string;
    status: 0 | 1;
    comments?: string;
}) => {
    try {
        return await request<null>(
            "/user/admin/audit_approval",
            "post",
            params
        );
    } catch (error) {
        throw error;
    }
};
